//
//  ClassColPushViewController.m
//  LiangYa_BObject
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 YuHao. All rights reserved.
//

#import "ClassColPushViewController.h"
#import "BuyViewController.h"

@interface ClassColPushViewController ()

@property (nonatomic, strong) UIButton *backB;

@end

@implementation ClassColPushViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIImageView *imageU = [[UIImageView alloc] init];
    [imageU sd_setImageWithURL:[NSURL URLWithString:self.image]];
    CGFloat imageW = imageU.image.size.width;
    CGFloat imageH = imageU.image.size.height;
    imageU.frame = CGRectMake(0, 0, ScreenWidth, ScreenWidth / imageW * imageH);
    [self.view addSubview:imageU];
    
    UIImageView *imageD = [[UIImageView alloc] initWithFrame:CGRectMake(0, ScreenWidth / imageW * imageH, ScreenWidth, Screenheight - ScreenWidth / imageW * imageH)];
    [imageD sd_setImageWithURL:[NSURL URLWithString:self.image]];
    [self.view addSubview:imageD];
    
    UIVisualEffectView *blurV = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    blurV.frame = imageD.bounds;
    [imageD addSubview:blurV];
    
    UILabel *brandL = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, ScreenWidth - 40, 25)];
    brandL.textColor = [UIColor whiteColor];
    brandL.font = [UIFont boldSystemFontOfSize:17];
    brandL.attributedText = [self shadowstr:self.brandName];
    [imageD addSubview:brandL];
    
    UILabel *contentL = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, ScreenWidth - 40, imageD.frame.size.height - 200)];
    contentL.numberOfLines = 0;
    contentL.textColor = [UIColor whiteColor];
    contentL.font = [UIFont boldSystemFontOfSize:15];
    contentL.attributedText = [self shadowstr:self.content];
    [imageD addSubview:contentL];
    
    UILabel *priceL = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 190, imageD.frame.size.height - 120 , 90, 20)];
    priceL.textColor = [UIColor redColor];
    priceL.font = [UIFont boldSystemFontOfSize:15];
    priceL.attributedText = [self shadowstr:self.price];
    [imageD addSubview:priceL];
    
    UILabel *soldNumL = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 100, imageD.frame.size.height - 120 , 90, 20)];
    soldNumL.textColor = [UIColor whiteColor];
    soldNumL.font = [UIFont systemFontOfSize:14];
    soldNumL.attributedText = [self shadowstr:self.soldNum];
    [imageD addSubview:soldNumL];
    
    UIButton *buyBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    buyBtn.frame = CGRectMake(ScreenWidth - 100, Screenheight - 60, 80, 40);
    buyBtn.layer.cornerRadius = 5;
    buyBtn.backgroundColor = [UIColor whiteColor];
    [buyBtn setTitle:@"购买" forState:UIControlStateNormal];
    [buyBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:buyBtn];
    [buyBtn addTarget:self action:@selector(buyAction:) forControlEvents:UIControlEventTouchUpInside];
    

    // 返回按钮
    self.backB = [UIButton buttonWithType:UIButtonTypeSystem];
    _backB.backgroundColor = [UIColor colorWithRed:1.000 green:0.000 blue:0.139 alpha:1.000];
    _backB.frame = CGRectMake(20, Screenheight - 60, 40, 40);
    _backB.layer.cornerRadius = 20;
    UIImage *backI = [[UIImage imageNamed:@"picture1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [_backB setImage:backI forState:UIControlStateNormal];
    [_backB setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    [_backB addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_backB];
    
    
}

- (void)buyAction:(UIButton *)btn
{
    BuyViewController *buyVC = [[BuyViewController alloc] init];
    buyVC.urlStr = self.urlStr;
    [self presentViewController:buyVC animated:YES completion:^{
        
    }];
}

- (NSMutableAttributedString *)shadowstr:(NSString *)string
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:string attributes:nil];
    NSShadow *shadow = [[NSShadow alloc]init];
    shadow.shadowColor = [UIColor grayColor];
    shadow.shadowOffset = CGSizeMake(1, 1);
    [str addAttributes:@{NSShadowAttributeName:shadow} range:NSMakeRange(0, str.length)];
    return str;
}

- (void)backAction:(UIButton *)btn
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
